package com.thewaybetter.modules.client.pages;

import java.util.Date;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.thewaybetter.modules.client.composites.MessagePanel;
import com.thewaybetter.modules.client.services.IdeaService;
import com.thewaybetter.modules.client.services.IdeaServiceAsync;

public class AboutWindow {

	private final DialogBox box = new DialogBox(true);
	private MessagePanel mp;
	
	public AboutWindow(MessagePanel panel) {
		mp = panel;
		configure();
	}
	
	private void configure(){
		box.setText("About The Way Better");
		VerticalPanel vp = new VerticalPanel();
		HorizontalPanel hp = new HorizontalPanel();
		HTML html = new HTML("<div id='closeWinBtn'></div><h1>The Way Better</h1>" +
				"<b>Version: 1.0</b><br/>" +
				"Updated at: " + new Date(109,6,8).toLocaleString() +
				"<br/>" +
				"This site is a alpha preview" +
				"<br/>Come back often to see the changes (We are going to update it almost every day).<br/><br/>" +
				"And visit the <a href='http://code.google.com/p/thewaybetter'>project site</a> to get more info on the project.<br/><br/>" +
				"If you want to contact me please send an email to <a href='mailto:brunogb@gmail.com'>brunogb@gmail.com</a> or <a href='mailto:fabiovl@gmail.com'>fabiovl@gmail.com</a><br/><br/>");
		Button btnClearAll = new Button("Clear all the data of the site");
		vp.add(html);
		vp.add(new Label("Just click outside of this popup to close it or you can also"));
		vp.add(btnClearAll);
		vp.add(new HTML("<br/>"));
		box.setWidget(vp);
		
		btnClearAll.addClickHandler(new  ClickHandler(){
			public void onClick(ClickEvent event) {
				final IdeaServiceAsync service = GWT.create(IdeaService.class);
				service.clearAll(new AsyncCallback<String>(){
					public void onFailure(Throwable caught) {}
					public void onSuccess(String result) {
						mp.clearMessages();
						box.hide();
					}
				});
			}
		});
	}
	public void show(){
		box.center();
	}
	
}
